/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: CommonExceptionHandler
 * Author:   zhouheng
 * Date:     2019/4/2 23:27
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.onesquare.user.exception;

import com.onesquare.common.entity.Result;
import com.onesquare.common.exception.CommonException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 〈一句话功能简述〉<br> 
 * 〈全局异常处理类〉
 *
 * @author zhouheng
 * @create 2019/4/2
 * @since 1.0.0
 */

@ControllerAdvice
@ResponseBody
public class CommonExceptionHandler {
    @ExceptionHandler(CommonException.class)
    public ResponseEntity<Result> handleException(Exception e) {
        Result result = new Result();
        CommonException commonException = (CommonException) e;
        result.setCode(commonException.getCode());
        result.setMessage(e.getMessage());

        return new ResponseEntity(result, HttpStatus.OK);
    }
}